#include <stdio.h>
#include <math.h>

static double rssi_to_distance(double txPower, double rssi)
{
    double refDistance = 1.0;
    double pathLoss = 3.2;

    double c1 = txPower;
    double c2 = pathLoss;

    double fm = (c1 - rssi) / (10 * c2);
    printf("fm = %lf\n",fm);
    double fp = pow(10, fm);

    double ret = refDistance * fp / 100;

    return ret;
}

int main()
{
    double tx = 21.0;
    double rssi = -41.0;

    printf("txPower %lf\n", tx);

    printf("%-20s\t%-10s\n", "Distance", "RSSI");
    printf("%-20lf\t%-10lf\n", rssi_to_distance(tx, rssi), rssi);

    int i = 2;
    for (; i <= 10; ++i)
    {
        rssi = -1 * i * 10;
        printf("%-20lf\t%-10lf\n", rssi_to_distance(tx, rssi), rssi);
    }

    return 0;
}